#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int N = 1e5 + 10;
int h[N], ne[N], e[N], w[N], idx;
int arr[N];
bool st[N];
void add(int a, int b, int c)
{
    e[idx] = b, ne[idx] = h[a], h[a] = idx, w[idx++] = c;
}
int main()
{
    int n;
    cin >> n;
    int a, b, c;
    memset(h, -1, sizeof h);
    n--;
    while (n--)
    {
        cin >> a >> b >> c;
        add(a, b, c);
        add(b, a, c);
    }
    queue<int> q;
    q.push(1);
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        st[u] = true;
        for (int i = h[u]; i != -1; i = ne[i])
        {
            int j = e[i];
            if (!st[j])
            {
                q.push(j);
                arr[j] = max(arr[j], w[i] + arr[u]);
                st[j] = true;
            }
        }
    }

    int ma = -1;
    int maxi = -1;
    for (int i = 1; i <= n; i++)
    {
        if (arr[i] > ma)
        {
            ma = arr[i];
            maxi = i;
        }
    }
    memset(arr, 0, sizeof arr);
    memset(st, false, sizeof st);
    q.push(maxi);
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        st[u] = true;
        for (int i = h[u]; i != -1; i = ne[i])
        {
            int j = e[i];
            if (!st[j])
            {
                q.push(j);
                arr[j] = max(arr[j], w[i] + arr[u]);
                st[j] = true;
            }
        }
    }
    for (int i = 1; i <= n; i++)
        cout << arr[i] << ' ';
    cout << endl;
    cout << *max_element(arr + 1, arr + n + 2) << endl;
    return 0;
}